package com.company.statistician;

import com.company.TrianglePacket;
import com.company.exception.NoMatchException;
import com.company.graphgetter.EdgeGetterWithGraph;
import com.company.graphgetter.GraphGetter;

import java.util.ArrayList;
import java.util.List;

public abstract class EdgeStatistician implements Statistician {
    protected List<TrianglePacket> edgePackets;

    public EdgeStatistician(GraphGetter graphGetter) throws NoMatchException {
        equipData(graphGetter);
    }

    @Override
    public void equipData(GraphGetter graphGetter) throws NoMatchException {
        if (!(graphGetter instanceof EdgeGetterWithGraph)) {
            throw new NoMatchException("Getter is not the type of EdgeGetterWithGraph");
        }
        EdgeGetterWithGraph getter = (EdgeGetterWithGraph) graphGetter;
        edgePackets = CopyList(getter.edgeRanks());
    }

    public abstract void calcData();

    public abstract Object outputData();

    private List<TrianglePacket> CopyList(List<TrianglePacket> list) {
        ArrayList<TrianglePacket> nodeTrianglePackets = new ArrayList<>(list);
        return nodeTrianglePackets;
    }
}
